﻿#include "tpiece.h"

TPiece::TPiece()
{
    m_Quadrados << QRect(QPoint(0, 0), s_QuadLength);
    m_Quadrados << QRect(QPoint(s_QuadLength.width(), 0), s_QuadLength);
    m_Quadrados << QRect(QPoint(2 * s_QuadLength.width(), 0), s_QuadLength);
    m_Quadrados << QRect(QPoint(s_QuadLength.width(), s_QuadLength.height()),
                                s_QuadLength);
    m_Cor = QColor(79,157,0,220);
}

QList<QRect> TPiece::rotacione(){
    QTransform tab;
    QList<QRectF> tempF;
    QList<QRect> ret;

    tab = tab.rotate(90.0);

    for(int i = 0;i < m_Quadrados.size();++i)
        tempF << QRectF(m_Quadrados[i]);

    for(int i = 0;i < tempF.size();++i){
        if(i == 1) i++;
        tempF[i].moveTo((tempF[i].x() - tempF[1].center().x()),
                        (tempF[i].y() - tempF[1].center().y()));
        tempF[i].setTopLeft(tempF[i].bottomLeft()*tab);
        tempF[i].setSize(QSizeF(s_QuadLength));
        tempF[i].moveTo((tempF[i].x() + tempF[1].center().x()),
                        (tempF[i].y() + tempF[1].center().y()));
    }

    for(int i = 0;i < tempF.size();++i)
        ret << tempF[i].toRect();

    return ret;
}
